Merged
Conversation
Member
|
一个兼容TM的示例,很极端的用法,说实话不是很想咬文嚼字,内部实现本来就不一样,硬要一致会多一些莫名其妙的代码,不用完全一致 // ==UserScript==
// @name New Userscript REDV-1
// @namespace https://docs.scriptcat.org/
// @version 0.1.0
// @description try to take over the world!
// @author You
// @match https://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=example.com
// @early-start
// @run-at document-start
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_setValues
// @grant GM_getValues
// ==/UserScript==
console.log(GM_getValue("circular"), GM_getValues(["circular"])); // undefined {}
GM_setValues({ "circular": "123" });
console.log(GM_getValue("circular"), GM_getValues(["circular"])); // 123 {"circular":123}
GM_setValues({ "circular": window });
console.log(GM_getValue("circular"), GM_getValues(["circular"])); // undefined {circular: undefined}
GM_setValue("circular", window)
console.log(GM_getValue("circular"), GM_getValues(["circular"])); // undefined {circular: undefined} |
Collaborator
Author
你的 undefined 会删键呀 |
cyfung1031
commented
Feb 3, 2026
| a.scriptRes.value[key] = value; | ||
| a.sendMessage("GM_setValue", [id, key, value]); | ||
| if (value === undefined) { | ||
| a.sendMessage("GM_setValue", [id, key]); |
Collaborator
Author
There was a problem hiding this comment.
上面的 a.sendMessage("GM_setValue", [id, key]); 会有 delete a.scriptRes.value[key]; 但这个是 a.scriptRes.value[key] = undefined;
你要不要统一一下呀?
Member
There was a problem hiding this comment.
故意为之,兼容TM,删除了key,但是这一次通过 GM_getValues 可以获取到 key,但是刷新页面就没有这个key了
cyfung1031
commented
Feb 3, 2026
| value_ = customClone(value_); | ||
| } | ||
| // customClone 可能返回 undefined | ||
| valueStore[key] = value_; |
Collaborator
Author
There was a problem hiding this comment.
上面有 delete valueStore[key];
这里是 valueStore[key] = undefined;
你要不要统一一下呀?
cyfung1031
commented
Feb 3, 2026
Comment on lines
273
to
288
| if (value === undefined) { | ||
| delete a.scriptRes.value[key]; | ||
| a.sendMessage("GM_setValue", [id, key]); | ||
| } else { | ||
| // 对object的value进行一次转化 | ||
| if (value && typeof value === "object") { | ||
| value = structuredClone(value); | ||
| value = customClone(value); | ||
| } | ||
| // customClone 可能返回 undefined | ||
| a.scriptRes.value[key] = value; | ||
| a.sendMessage("GM_setValue", [id, key, value]); | ||
| if (value === undefined) { | ||
| a.sendMessage("GM_setValue", [id, key]); | ||
| } else { | ||
| a.sendMessage("GM_setValue", [id, key, value]); | ||
| } | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
Suggested change
| } | |
| // 对object的value进行一次转化 | |
| if (value && typeof value === "object") { | |
| value = customClone(value); | |
| // customClone 可能返回 undefined | |
| } | |
| if (value === undefined) { | |
| delete a.scriptRes.value[key]; | |
| a.sendMessage("GM_setValue", [id, key]); | |
| } else { | |
| a.scriptRes.value[key] = value; | |
| a.sendMessage("GM_setValue", [id, key, value]); | |
| } |
这样简单一点不好吗
cyfung1031
commented
Feb 3, 2026
Comment on lines
304
to
317
| for (const [key, value] of Object.entries(values)) { | ||
| let value_ = value; | ||
| if (value_ === undefined) { | ||
| if (valueStore[key]) delete valueStore[key]; | ||
| } else { | ||
| // 对object的value进行一次转化 | ||
| if (value_ && typeof value_ === "object") { | ||
| value_ = structuredClone(value_); | ||
| value_ = customClone(value_); | ||
| } | ||
| // customClone 可能返回 undefined | ||
| valueStore[key] = value_; | ||
| values[key] = value_; | ||
| } | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
Suggested change
| } | |
| for (const [key, value] of Object.entries(values)) { | |
| let value_ = value; | |
| // 对object的value进行一次转化 | |
| if (value_ && typeof value_ === "object") { | |
| value_ = customClone(value_); | |
| // customClone 可能返回 undefined | |
| } | |
| if (value_ === undefined) { | |
| if (valueStore[key]) delete valueStore[key]; | |
| } else { | |
| valueStore[key] = value_; | |
| } | |
| } |
这样简单一点不好吗
Member
|
单测出问题了 |
Member
TM会删啊,你看刷新后,第二次进来就知道了 |
CodFrm
added a commit
that referenced
this pull request
Feb 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述 Descriptions
注:日后把一些共通页面环境的东西都拉去
global.ts(1.3.x) [ 例如 performance pageDispatch, ... ]避免页面内容修改过而无法运行内部处理
变更内容 Changes
截图 Screenshots